// pages/live/record/record.js
import {
    HTTP
} from '../../../utils/http.js'
let ajax = new HTTP()
const app = getApp()
Page({
    data: {
        recordLive: [],
        videoIndex: null,
        name: "",
        pic: "",
        objFit: "fill",
        showPlayBtn: false
    },
    onLoad (options) {
        wx.showLoading({
            title: '加载中',
        })
        let id = options.id
        this.setData({
            name: options.name,
            pic: options.pic
        })
        this._getRecordList(id)
    },
    onBindPlay(e) {
        let index = e.currentTarget.dataset.index
        //console.log("index:" + index, "this.data.videoIndex:" + this.data.videoIndex)
        if (this.data.videoIndex == null) {
            this.setData({
                videoIndex: index
            })
            let videoContext = wx.createVideoContext('video' + index)
            videoContext.play()
        } else {
            let videoContextPrev = wx.createVideoContext('video' + this.data.videoIndex)
            videoContextPrev.stop()
            this.setData({
                videoIndex: index
            })
            let videoContextCurrent = wx.createVideoContext('video' + index)
            videoContextCurrent.play()
        }
    },
    // 是否全屏
    fullscreenChange (event) {
        console.log(event.detail.fullScreen)
        if (event.detail.fullScreen) {
            this.setData({
                objFit: "contain",
                showPlayBtn: true
            })
        } else {
            this.setData({
                objFit: "fill",
                showPlayBtn: false
            })
        }
    },
    onShareAppMessage () {

    },
    // 请求直播列表
    _getRecordList(id) {
        ajax.request({
            method: "GET",
            url: "activelist/actvideo",
            data: {
                id: id
            },
            success: (res) => {
                wx.hideLoading()
                this.setData({
                    recordLive: res.data
                })
            }
        })
    }
})